package com.yuxi.service.impl;

import com.yuxi.enums.ProductNewFlagEnum;
import com.yuxi.enums.ProductRecommendFlagEnum;
import com.yuxi.enums.ProductTypeTypeFlagEnum;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.yuxi.modelExt.ProductExt;
import com.yuxi.dao.IProductDao;
import com.yuxi.searchExt.ProductSearchExt;
import com.yuxi.pubInter.IBaseDao;
import com.yuxi.pubInter.AbstractBaseService;
import com.yuxi.service.IProductService;
import lombok.extern.slf4j.Slf4j;
import com.yuxi.common.StringUtil;
import com.yuxi.common.SkList;
import com.yuxi.pubInter.exception.SkException;

import java.util.List;


/**
*    @author sunke
*    @Date 2023-10-13 10:05:04
*    @description ProductService      产品
*/
@Service(value = "productService")
@Slf4j
public class ProductServiceImpl extends AbstractBaseService<ProductExt, ProductSearchExt,String> implements IProductService {

    @Resource(name = "productDao")
    private IProductDao productDao;

    @Override
    public IBaseDao<ProductExt, ProductSearchExt,String> getDao() {
        return productDao;
    }


    @Override
    public List<ProductExt> getRecommendList(int size) {
        try {
            ProductSearchExt searchExt=ProductSearchExt.getInstance();
            searchExt.setRecommendFlagIn(SkList.getInstance().addObjToList(ProductRecommendFlagEnum.Y.getType().intValue()));
            searchExt.setTypeFlagIn(SkList.getInstance().addObjToList(ProductTypeTypeFlagEnum.PRODUCT_TYPE.getType()));
            if(size==-1){
                return getAllList(searchExt);
            }
            searchExt.setOrderBy("p_sort_num");
            searchExt.setPageSize(size);
            return getList(searchExt);
        } catch (SkException e) {
            return null;
        }

    }

    /**
     * 推荐产品
     *
     * @return
     */
    @Override
    public ProductExt getNew() {
        ProductSearchExt searchExt=ProductSearchExt.getInstance();
        searchExt.setNewFlagIn(SkList.getInstance().addObjToList(ProductNewFlagEnum.Y.getType().intValue()));
        searchExt.setTypeFlagIn(SkList.getInstance().addObjToList(ProductTypeTypeFlagEnum.PRODUCT_TYPE.getType()));
        return getDetailBySearch(searchExt);

    }
}